#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <queue>
#define DEBUG 1
using namespace std;
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0, - 1,1 };
int main() {
    queue<pair<int, int>> p;
    int n, m;
    int ret = 0;
    cin >> n >> m;
    vector<vector<bool>> check(n, vector<bool>(m));
    vector<vector<char>> c(n, vector<char>(m));
    vector<vector<int>> num(n, vector<int>(m));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> c[i][j];
            if (c[i][j] == 'k')
            {
                p.push(make_pair(i, j));
                check[i][j] = true;
            }
        }
    }
    while (!p.empty())
    {
        int a = p.front().first;
        int b = p.front().second;
        for (int k = 0; k < 4; k++)
        {
            int x = a + dx[k];
            int y = b + dy[k];
            if (x >= n || y >= m || x < 0 || y < 0)
            {
                continue;
            }
            if (c[x][y] == '.'&&check[x][y]==false)
            {
                p.push(make_pair(x, y));
                num[x][y] = num[a][b] + 1;
                check[x][y] = true;
            }
            if (c[x][y] == 'e' && check[x][y] == false)
            {
                num[x][y] = num[a][b] + 1;
                ret++;
                check[x][y] = true;
            }
        }
        p.pop();
    }
#ifdef DEBUG
    for (auto p : num)
    {
        for (auto e : p)
        {
            cout << e << ' ';
        }
        cout << endl;
    }
#endif
    cout << ret;
    return 0;
}